<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>门锁列表</title>
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="stylesheet" type="text/css" href="bootstrap/dist/css/bootstrap.min.css" />
		<link rel="stylesheet" type="text/css" href="css/bootstrap-datetimepicker.min.css" />
		<!--<link rel="stylesheet" type="text/css" href="css/public.css" />-->
	</head>
	<style type="text/css">
		.remove {
			cursor: pointer;
		}
		
		.remove:hover {
			color: red;
		}
		
		.pagination span {
			font: 14px/34px "";
			padding: 0 5px;
		}
		
		.form-control {
			display: inline-block;
			width: 100px;
		}
		
		.select {
			width: 120px;
		}
		
		.search {
			width: 155px;
		}
		
		.header {
			/*border-bottom: 1px solid #fefefe;*/
		}
		
		.header span {
			padding: 0 5px;
		}
		
		.table_cla {
			height: 560px;
		}
	</style>

	<body>
		<div id="app" style="width: 100%; margin: 0 auto;padding:0 20px;">

			<div class="header" style="margin-top: 20px;">
				<span>开始时间:</span><input class="time-input form-control" type="text" id="datetimepicker" v-model="start">
				<!--<p>{{start}}</p>-->
				<span>结束时间:</span><input class="time-input form-control" type="text" id="datetimepicker1" v-model="end">
				<!--<span>选择区域：</span>
				<select name="" class="form-control select">
					<option value="000">请选择区域</option>
					<option v-for="index in leixing" :value="index.id">{{index.name}}</option>

				</select>-->
				<input type="text" class="form-control search" name="search1" id="search1" value="" v-model="searchmain" placeholder="输入需要查询的内容" />

				<button type="button" class="btn btn-info" data-dismiss="modal" @click="search">搜索</button>
				<button type="button" class="btn btn-info" data-dismiss="modal" @click="addMensuo">增加</button>

			</div>
			<div class="table_cla">
				<table class="table">
					<caption>门锁列表</caption>
					<thead>
						<tr>
							<th>物业</th>
							<th>小区</th>
							<th>区域</th>
							<th>楼宇</th>
							<th>单元</th>
							<th>类型</th>
							<th>门锁名字</th>
							<th>锁号</th>
							<th>删除</th>
						</tr>
					</thead>
					<tbody v-for="(tt,index) in table">
						<tr>
							<td v-text="tt.organizename"></td>
							<td v-text="tt.areaname"></td>
							<td v-text="tt.kind"></td>
							<td v-text="tt.buildname"></td>
							<td v-text="tt.units"></td>
							<td v-text="tt.iscloud"></td>
							<td v-text="tt.doorlockname"></td>
							<td v-text="tt.doorlocksn"></td>
							<td @click="remove($event)" data-toggle="modal" data-target="#myModalremove" class="remove">
								<span v-if="panduan" class="glyphicon glyphicon-trash"></span>
								<span class="hanyouid" style="display: none;" v-text="tt.doorlockid"></span>
							</td>
						</tr>

					</tbody>
				</table>

			</div>
			<ul  class="pagination">
				<span v-text="count_all"></span>				
				<!--<li v-show="current != 1" @click="current-- && goto(current--)">
					<a href="#">上一页</a>
				</li>-->
				<li v-for="index in pages" @click="goto(index)" :class="{'active':current == index}" :key="index">
					<a href="#" v-text="index"></a>
				</li>
				<!--<li v-show="allpage != current && allpage != 0 " @click="current++ && goto(current++)">
					<a href="#">下一页</a>
				</li>-->
				<span>跳到:</span>
				<!--<input style="width: 50px;height: 34px;" min="1" max="{{allpage}}" type="number" name="goto" id="goto" v-model="jump" />-->
				<input style="width: 50px;height: 28px;" name="goto" id="goto" v-model="jump" type="text" name="" oninput="value=value.replace(/[^\d]/g,'')">
				<span>页</span>
				<!--<input type="button"   />-->
				<button type="button" id="gotoo" @click="goto(jump)" class="btn btn-danger ">确定 </button>
			</ul>
			<!-- 模态框（Modal） -->
			<div class="modal fade" id="myModalremove" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
							<h4 class="modal-title" id="myModalLabel">是否确认删除</h4>
						</div>
						<div class="modal-body">删除后数据无法找回</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
							<button type="button" id="remove" class="btn btn-danger remove" @click="sureremove">确定删除</button>
						</div>
					</div>
					<!-- /.modal-content -->
				</div>
				<!-- /.modal -->
			</div>

			<!-- 模态框（Modal）提示信息 -->
			<div class="modal fade" id="myModal_tips" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
							<h4 class="modal-title" id="myModalLabel">提示信息</h4>
						</div>
						<div class="modal-body" id="tips" v-text="tips_modal">

						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						</div>
					</div>
				</div>
			</div>

		</div>

	</body>

</html>
<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
<script src="bootstrap/dist/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/bootstrap-datetimepicker.js" type="text/javascript" charset="utf-8"></script>
<script src="js/bootstrap-datetimepicker.zh-CN.js" type="text/javascript" charset="utf-8"></script>
<script src="js/public.js" type="text/javascript" charset="utf-8"></script>

<script>
	//	var urlr = "http://192.168.0.30:8085"
	new Vue({
		el: '#app',
		data: {
			val_te: "",
			page_show: false,
			urlr: "",
			current: 1,
			showItem: 5,
			parameter: "",
			allpage: "",
			jump: "",
			start: "",
			end: "",
			searchmain: "",
			panduan: "",
			merchantid: "",
			areaid: '',
			createusername: "",
			tips_modal: "",
			count_all:"",
			leixing: [{
				name: '公共区域',
				id: "1"
			}, {
				name: '楼宇门锁',
				id: "2"
			}],
			removeid: "",
			table: [{
					//					organizename: "woke",
					//					areaname: "xiaoqu",
					//					kind: "quyu",
					//					louyu: "louyu",
					//					buildname: "danyuan",
					//					doorlockname: "mingzi",
					//					doorlocksn: "suohao",
					//					doorlockid: "1221221"
				},

			]
		},
		//计算属性
		computed: {

		},
		created: function() {
			var that = this;
			var aa = getUrl();
			that.urlr = aa;
		},
		mounted: function() {
			this.parameter = window.location.search;
			var userid = getUrlParam('userid');
			var createusername = getUrlParam('realname');
			var merchantid = getUrlParam('merchantid');
			this.merchantid = merchantid;
			var areaid = getUrlParam('areaid');
			this.areaid = areaid;
			if(userid == null || userid == '') {
				//				alert("用户id不能为空")
				this.tips_modal = "用户id不能为空";
				$('#myModal_tips').modal('show');
				this.val_te = true;
				return;
			}
			if(createusername == null || createusername == '') {
				//				alert("用户姓名不能为空");
				this.tips_modal = "用户姓名不能为空";
				$('#myModal_tips').modal('show');
				this.val_te = true;
				return;
			}
			if(areaid == null || areaid == '') {
				//				alert("小区id不能为空");
				this.tips_modal = "小区id不能为空";
				$('#myModal_tips').modal('show');
				this.val_te = true;
				return;
			}
			if(merchantid == null || merchantid == '') {
				//				alert("物业id不能为空");
				this.tips_modal = "物业id不能为空";
				$('#myModal_tips').modal('show');
				this.val_te = true;
				return;
			}
			this.datePickerInit();
			var datainit = {
				startday: this.start,
				endday: this.end,
				organizeid: this.merchantid,
				pagenumber: 1,
				pagesize: 10,
				areaid: this.areaid,
				selectinfo: this.searchmain,
			}
			if(this.val_te != true) {

				this.jiazai(datainit);
				this.table = ""
			}
		},
		computed: {
			pages: function() {
				var pag = [];
				if(this.current < this.showItem) { //如果当前的激活的项 小于要显示的条数
					//总页数和要显示的条数那个大就显示多少条
					var i = Math.min(this.showItem, this.allpage);
					while(i) {
						pag.unshift(i--);
					}
				} else { //当前页数大于显示页数了
					var middle = this.current - Math.floor(this.showItem / 2), //从哪里开始
						i = this.showItem;
					if(middle > (this.allpage - this.showItem)) {
						middle = (this.allpage - this.showItem) + 1
					}
					while(i--) {
						pag.push(middle++);
					}
				}
				return pag
			},
			//			iskind: function() {
			//				return this.table.kind == 1 ? "公共区域" : "楼宇门锁"
			//			},
			//			iscloud: function() {
			//				debugger
			//				return this.table.iscloud == 1 ? "普通蓝牙门锁" : "云对讲"
			//			}
		},
		methods: {
			//增加
			addMensuo: function() {
				var url_index = "index.html" + this.parameter;
				//				console.log(url_index)
				window.location.href = url_index;
			},
			datePickerInit: function() {
				//debugger
				var d, s;
				var self = this;
				self.start = s;
				$('#datetimepicker').datetimepicker({
					minView: "month", //选择日期后，不会再跳转去选择时分秒 
					language: 'zh-CN',
					format: 'yyyy-mm-dd',
					todayBtn: 1,
					autoclose: 1,
				});
				$('#datetimepicker1').datetimepicker({
					startDate: s,
					minView: "month", //选择日期后，不会再跳转去选择时分秒 
					language: 'zh-CN',
					format: 'yyyy-mm-dd',
					todayBtn: 1,
					autoclose: 1,
				});
				$('#datetimepicker').datetimepicker()
					.on('hide', function(ev) {
						var value = $("#datetimepicker").val();
						self.start = value;
						$('#datetimepicker1').datetimepicker('setStartDate', self.start);
						self.end = "";
					});
				$('#datetimepicker1').datetimepicker()
					.on('hide', function(ev) {
						var value = $("#datetimepicker1").val();
						self.end = value;

					});
			},

			remove: function($event) {
				var this1 = $event.currentTarget;
				var sss = this1.children[1].innerHTML;
				this.removeid = sss;

			},
			//加载数据
			jiazai: function(e) {

				var data = JSON.stringify(e);
				var that = this;
				$.ajax({
					contentType: "application/json; charset=utf-8",
					type: "POST",
					url: that.urlr + "/doorLock/selectDoorLockList",
					data: data,
					async: true,
					dataType: "json",
					success: function(msg) {
						if(msg.code == 200) {
							var aa = JSON.parse(msg.returnString);
							for(var i = 0; i < aa.length; i++) {
								if(aa[i].iscloud == 1) {
									aa[i].iscloud = "普通蓝牙门锁"
								} else if(data[i].iscloud == 2) {
									data[i].opentype = "云对讲"
								}
								if(aa[i].kind == 1) {
									aa[i].kind = "公共区域"
								} else if(aa[i].kind == 2) {
									aa[i].kind = "楼宇门锁"
								}
							}

							that.table = aa;

							if(that.table.length > 0) {
								that.panduan = true;
//								that.page_show = true;
							} else {
								that.panduan = false;

							}
							that.count_all = "共" + msg.count + "条";
							var yu = msg.count % 10;
							if(yu == 0) {
								that.allpage = parseInt(msg.count / 10);
							} else {
								that.allpage = parseInt(msg.count / 10) + 1;
							}

						} else {
							that.tips_modal = msg.disp;
							$('#myModal_tips').modal('show');
						}
					},
					error: function() {
						//						alert("获取信息失败");
						that.tips_modal = "获取信息失败";
						$('#myModal_tips').modal('show');
					}
				});

			},

			sureremove: function() {
				//				debugger
				$('#remove').prop('disabled', true);
				var that = this;
				var aa = that.removeid;
				var data = {
					"doorlockid": aa
				}
				data = JSON.stringify(data);
				$.ajax({
					contentType: "application/json; charset=utf-8",
					type: "POST",
					url: that.urlr + "/doorLock/deleteDoorLock",
					data: data,
					async: true,
					dataType: "json",
					success: function(msg) {
						//						console.log(msg);
						if(msg.code == 200) {
							$('#myModalremove').modal('hide');
							that.tips_modal = "删除成功";
							$('#myModal_tips').modal('show');
							var datainit = {
								"startday": that.start,
								"endday": that.end,
								"organizeid": "",
								"pagenumber": 1,
								"pagesize": 10
							}
							that.jiazai(datainit);
						} else {
							that.tips_modal = msg.disp;
							$('#myModal_tips').modal('show');
							$('#remove').prop('disabled', false);
						}
					},
					error: function() {
						//						alert("获取信息失败");
						that.tips_modal = "获取信息失败";
						$('#myModal_tips').modal('show');
						$('#remove').prop('disabled', false);
					}
				});
			},
			goto: function(index) {
				if(index == this.current) return;
				if(index > this.allpage) {
					return
				}
				//				debugger
				var re = /^[1-9]+[0-9]*]*$/ //判断正整数      // /^[0-9]+.?[0-9]*$/; //判断字符串是否为数字  
				if(!re.test(index)) {
					return false;
				}
				this.current = index;
				//				console.log(index)
				//				alert("去请求吧")
				var datainit = {
					startday: this.start,
					endday: this.end,
					organizeid: this.merchantid,
					pagenumber: index,
					pagesize: 10,
					areaid: this.areaid,
					selectinfo: this.searchmain,
				}
				this.jiazai(datainit);
				//这里可以发送ajax请求
			},
			search: function() {
				var that = this;
				var datainit = {
					startday: this.start,
					endday: this.end,
					organizeid: this.merchantid,
					pagenumber: 1,
					pagesize: 10,
					areaid: this.areaid,
					selectinfo: this.searchmain,
				}
				if(that.val_te != true) {
					this.jiazai(datainit);
				} else {
					//					alert("非法登录");
					that.tips_modal = "非法登录";
					$('#myModal_tips').modal('show');
				}

			}
		},

	})
</script>